package bavaria.hightech.banking.bank;

import java.math.BigInteger;

public class Money {

	public final static Money ZERO = new Money(BigInteger.ZERO, Currency.EURO);

	private BigInteger money; // weil es immutable ist
	private Currency currency;// enum ist immer immutable q_q

	public Money(BigInteger money, Currency currency) {
		this.money = money;
		this.currency = currency;
	}

	public Money(int money, Currency currency) {
		this(new BigInteger(String.valueOf(money)), currency);
	}

	public Money(String money, Currency currency) {
		this(new BigInteger(money), currency);
	}

	public Money add(Money amount) {
		return new Money(money.add(amount.money), currency);
	}

	public Money subtract(Money amount) {
		return new Money(money.subtract(amount.money), currency);
	}

	public Money calculateInterest(float value) {
		long result = (long) (money.intValue() * value);
		return new Money(BigInteger.valueOf(result), currency);
	}

	public Money negate() {
		return new Money(money.negate(), currency);
	}

	public boolean same(Money other) {
		if (!money.equals(other.money))
			return false;
		if (currency != other.currency)
			return false;
		return true;
	}

	public boolean greaterThan(Money other) {
		if (money.compareTo(other.money) > 0) {
			return true;
		}
		return false;
	}

	public boolean greaterThanEquals(Money other) {
		if (money.compareTo(other.money) >= 0) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return "Money [money=" + money + ", currency=" + currency + "]";
	}

	public BigInteger getBigInteger() {
		return money;
	}
}